﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="detailandmed_asutamise_aeg", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(DetailandmedAsutamiseAeg))]
    public class DetailandmedAsutamiseAegSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IDetailandmedAsutamiseAeg clazz;
        
        public DetailandmedAsutamiseAegSerializer(IDetailandmedAsutamiseAeg clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.KaardiPiirkond!=null) {
                Writer.WriteStartElement("kaardi_piirkond");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KaardiPiirkond))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaardiNr!=null) {
                Writer.WriteStartElement("kaardi_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KaardiNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaardiTyyp!=null) {
                Writer.WriteStartElement("kaardi_tyyp");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KaardiTyyp))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KandeNr!=null) {
                Writer.WriteStartElement("kande_nr");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "int");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInt(((int)(clazz.KandeNr))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Sisu!=null) {
                Writer.WriteStartElement("sisu");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Sisu))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKpv!=null) {
                Writer.WriteStartElement("algus_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.AlgusKpv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKpv!=null) {
                Writer.WriteStartElement("lopp_kpv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.LoppKpv))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="kaardi_piirkond") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>kaardi_piirkond");
                }
                clazz.KaardiPiirkond = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kaardi_piirkond")).Value;
            }
            if (Reader.LocalName=="kaardi_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>kaardi_nr");
                }
                clazz.KaardiNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kaardi_nr")).Value;
            }
            if (Reader.LocalName=="kaardi_tyyp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>kaardi_tyyp");
                }
                clazz.KaardiTyyp = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kaardi_tyyp")).Value;
            }
            if (Reader.LocalName=="kande_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>kande_nr");
                }
                clazz.KandeNr = new global::Xtee.Core.Schema.XsdInt(Reader.ReadElementString("kande_nr")).Value;
            }
            if (Reader.LocalName=="sisu") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>sisu");
                }
                clazz.Sisu = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("sisu")).Value;
            }
            if (Reader.LocalName=="algus_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>algus_kpv");
                }
                clazz.AlgusKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("algus_kpv")).Value;
            }
            if (Reader.LocalName=="lopp_kpv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>detailandmed_asutamise_aeg>lopp_kpv");
                }
                clazz.LoppKpv = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("lopp_kpv")).Value;
            }
        }
    }
}
